package com.mzy.linear_struct.面试150题;

/**
 * @Author: mizy3
 * @Date: 2024/08/16/下午2:09
 * @Description:
 */
public class Pro58最后一个单词的长度 {
    public int lengthOfLastWord(String s) {
        boolean flag = false;

        char[] arr = s.toCharArray();
        int ans = 0;
        int i = arr.length - 1;

        while (arr[i] == ' '){
            i--;
        }


        for (; i >= 0; i--) {
            if(arr[i] == ' '){
                return ans;
            }
            ans++;

        }

        return ans;
    }
}
